<?php

namespace app\controller\web;

use app\service\LanguageTypeService;
use app\validate\LanguageTypeValidate;
use app\validate\PageValidate;
use share\utils\Helper;

class LanguageTypeController extends WebBaseController{

    public function initValidate(){        
        $this->validate = new LanguageTypeValidate();
    }

    /**
     * 新增项目信息
     */
    public function add_action(){
        $input = $this->check();
        $data = LanguageTypeService::addLanguage($input);
        return self::ok($data);
    }

    /**
     * 修改项目信息
     */
    public function edit_action(){
        $input = $this->check();
        $data = LanguageTypeService::updateLanguage($input);
        return self::ok($data);
    }

    /**
     * 删除项目信息
     */
    public function del_action(){
        $input = $this->check();
        $data = LanguageTypeService::delLanguage($input['language']);
        return self::ok($data);
    }

    /**
     * 列表 搜索
     */
    public function list_action(){        
        $page = $this->check('pageInfo',null,(new PageValidate()));  
        $data = LanguageTypeService::getListInfo([],$page);
        $data = Helper::arrayListReplaceKey($data,[
            'create_time' => 'createTime',
            'update_time' => 'updateTime',
        ]);
        $total = LanguageTypeService::getListCountInfo([]);
        return self::ok(self::formatPageData($page,$total,$data));
    }

    /**
     * 问题类型
     */
    public function simple_all_action(){
        $data =  LanguageTypeService::getAllByFilter([]);
        return self::ok(Helper::listArrayColumn($data,['language','name']));
    }
}